<?php

namespace App\Notifications;

use App\Models\Material;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class MaterialNotify extends Notification
{
    use Queueable;
    public $material;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(Material $materlal)
    {
        //
        $this->material = $materlal;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        //return ['mail'];   //邮件通知
        return ['database']; //站内信
    }

    /**
     * 获取通知的数组展示方式
     */
    public function toDatabase()
    {
        return [
            'material_id' => $this->material->id,
            'material_name' => $this->material->name,
            'initial_now' => $this->material->initial_now,
            'initial_min' => $this->material->initial_min,
            'title' => '库存报警！',
            'msg'=> '材料【'.$this->material->name.'】库存不足，当前库存为'.$this->material->initial_now.'，最低库存为'.$this->material->initial_min
        ];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}
